/***************************************************************************
 *	@file 		fetion_chat.cpp
 *	@Author 	baoyu0125@gmail.com
 *	@create		2011-7
 *	@version 	1.0.0
 *	@brief		definition of class Message, class Message contain information
 *				of fetion message
 *	@modify		none
 ***************************************************************************/

#ifndef FETION_CHAT_H
#define FETION_CHAT_H

class Contact;
class Message
{
public:
	friend class SipProcMessage;
	friend class currentUser;
	friend class Conversation;
	
	Message() : contact(NULL) {}
	void display();
private:
	std::string message;					/* message content  		*/
	std::string sipuri;						/* sender`s sip uri 		*/
	std::string pguri;
	int			callid;
	int			sysback;
	struct tm 	sendtime;					/* message sent time 		*/
	Contact *contact;
};

class FetionSip;
class Conversation
{
public:
	Conversation() : contact(NULL), currentSip(NULL)
	{
		unackedList.clear();
	}
	void new_conversation(Contact *ctct, FetionSip *sip);
	int input_message();
	int send_message();
	int send_sms_to_phone();
	int send_direct_message(const std::string &to);
	int remove_unacked(const int callid);
	int check_timeout();
private:
	Contact *contact;
	FetionSip *currentSip;
	std::string message;
	std::vector<Message> unackedList;
};

class Checker
{
public:
	Checker(boost::asio::io_service &io, int secs0) : 
		timer_(io, boost::posix_time::seconds(5)), secs(secs0) 
	{
		timer_.async_wait(boost::bind(&Checker::check_unacked, 
			this, boost::asio::placeholders::error));
	}
private:
	void check_unacked(const boost::system::error_code& error);
private:
	boost::asio::deadline_timer timer_;
	int secs;
};

#endif
